<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>评价管理</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
    <link type="text/css" rel="stylesheet" media="screen" href="__PUBLIC__/app/css/mrs.css{$JSDEBUG}"/>
    <link type="text/css" rel="stylesheet" media="screen" href="__PUBLIC__/app/css/media.css{$JSDEBUG}"/>
</head>
<body style="background:#efefef;">
	<include file="Public/customHeaderNoBack" title="评价管理"/>
 	<section class="pjdetail">
 		<div class="lists">
 			<if condition="$comments">
 			<foreach name="comments" item="comment">
		      <div class="mry_two mry_pj pjglhack">
		        <div class="mar_two_main">
		        	<if condition="!$comment['user_info']['headerimg']">
		            <img src="__PUBLIC__/app/images/mrydetail_05.png">
		            <else />
		            <img src="{$comment['user_info']['headerimg']}">
		           </if>
		            <ul>
		               <li>
		               <span>{$comment.user_info.mobile}</span>
		               <label>满意度：<for start="0" end="$comment['start']"><i></i></for>
		               </label>
		               </li>
		               <li><strong>专业：<span>{$comment.professional}分</span></strong><strong>守时：<span>{$comment.punctuality}分</span></strong><strong>沟通：<span>{$comment.communication}分</span></strong></li>
		               <li><p>{$comment.content}</p></li>
		            </ul>
		        </div>
		        <if condition="$comment['photos']">
		        <div class="pic_pin">
		        	<a href="{:U('/Comments/commentDetail/id/'.$comment['id'])}">
		             <ul>
		             	<foreach name="comment.photos" item="photo">
		                <li><img src="__UPLOADS__/Comment/{$photo.upload_number}/{$photo.img_name}"></li>
		                </foreach>
		             </ul>
		            </a>
		        </div>
		        </if>
		        <dd>{$comment.createtime|date="Y-m-d H:i:s",###}</dd>
		        <if condition="!$comment['reply']">
		         <a href="{:U('Comments/replyComment/id/'.$comment ['post_id'])}" class="pj_btn"><span>回复评论</span></a>
		        </if>
		     </div>
		      <if condition="$comment['reply']">
				<div class="mrs_addpj">
                      <div class="mrs_pjmain">
                    	<if condition="$comment['reply']['beautician']['profile_img']">
			           	<img src="__UPLOADS__/Profile/{$comment['reply']['beautician']['profile_img']}">
		            	<else />
		            	<img src="__PUBLIC__/app/images/defaultProfile.png">
		            	</if>
                        <span>{$comment.reply.beautician.name}</span>
                      </div>
                      <p><span>回复：</span>{$comment.reply.content}</p>
                      <if condition="$comment['reply']['photos']">
			          <div class="pic_pin">
			          	<a href="{:U('/Comments/commentDetail/id/'.$comment['reply']['id'])}">
				            <ul>
				            	<foreach name="comment.reply.photos" item="photo">
				                <li><img src="__UPLOADS__/Comment/{$photo.upload_number}/{$photo.img_name}"></li>
				                </foreach>
				            </ul>
			          	</a>
			          </div>
			          </if>
                      <dd>{$comment.reply.createtime|date="Y-m-d H:i:s",###}</dd>
        		</div>
		      </if>
		      </foreach>
		      <else />
		      <div class="no_bank"><h1>美滴滴</h1><p>没有评论数据~</p></div>
		     </if>
 		</div>
	</section>
	<script src="__FONT__/js/zepto.min.js"></script>
    <script src="__FONT__/js/dropload.min.js"></script>
    <script type="text/javascript" src="__FONT__/js/mustache.js"></script>
	<script>
    var hasMore = false,
    	nextPage = '{$nextPage}',
    	itemTemplete = '<div class="mry_two">'
	         +'<div class="mar_two_main">'
	         +'{{^userHasProfile}}<img src="__PUBLIC__/app/images/mrydetail_05.png">'
	         +'{{/userHasProfile}}{{#userHasProfile}}'
	         +'<img src="{{user_info.headerimg}}">{{/userHasProfile}}'
	         +'<ul>'
	         +'<li><span>{{user_info.mobile}}</span><label>{{{startHtml}}}</label></li>'
      		+'<li><strong>专业：<span>{{professional}}分</span></strong><strong>守时：<span>{{punctuality}}分</span></strong><strong>沟通：<span>{{communication}}分</span></strong></li>'
      		+'<li><p>{{content}}</p><dd>{{commentTime}}</dd></li>'
      		+'</ul>'
      		+'</div>'
      		+'{{#hasPhoto}}'
      		+'<div class="pic_pin"><a href="{:U(\'/Comments/commentDetail\')}?id={{id}}">'
      		+'<ul>'
      		+'{{#photos}}'
      		+'<li><img src="__UPLOADS__/Comment/{{upload_number}}/{{img_name}}"></li>'
      		+'{{/photos}}'
      		+'</ul>'
      		+'</a></div>{{/hasPhoto}}'
      		+'</div>{{#hasReply}}'
      		+'<div class="mrs_addpj">'
   		+'<h2>回复</h2>'
   	  	+'<div class="mrs_pjmain">'
                	+'<img src="{{#beauticianHasProfile}}__UPLOADS__/Profile/{{reply.beautician.profile_img}}{{/beauticianHasProfile}}{{^beauticianHasProfile}}__PUBLIC__/app/images/defaultProfile.png{{/beauticianHasProfile}}">'
   	              +'<dd><span>{{reply.beautician.name}}</span><label>{{reply.replyTime}}</label></dd>'
   	              +'<dd>{{reply.content}}</dd>'
   	          +'</div>'
   	          +'{{#hasPhoto}}'
   	          +'<div class="pic_pin"><a href="{:U(\'/Comments/commentDetail\')}?id={{comment.reply.id}}">'
   	            +'<ul>'
   	            	+'{{#reply.photos}}'
   	                +'<li><img src="__UPLOADS__/Comment/{{upload_number}}/{{img_name}}"></li>'
   	                +'{{/reply.photos}}'
   	            +'</ul>'
   	          +'</a></div>'
   	          +'{{/hasPhoto}}'
   	      +'</div>'
      		+'{{/hasReply}}';
     
    var loadMorePromise;
	function loadMore() {
   		if (!hasMore) {
    		return false;
    	}
    	
   		if (loadMorePromise && loadMorePromise.state == 'pending') {
   			return false;
   		}
   		
   		loadMorePromise = $.ajax({
            type: 'GET',
            url: nextPage,
            dataType: 'json',
            success: function(result){
            	if (result.status == 1) {
            		var itemHtml = '';
            		if (!$.isEmptyObject(result.data)) {
            			data = result.data;
            			for(var i in data){
            				var comment = data[i];
					   		
					   		var startHtml = '';
	  						var start = Math.floor(parseFloat(comment.avg_score));
	  						for (var j = 0 ; j < 5; j++) {
	  							if (start > j) {
	  								startHtml += '<i></i>';
	  							}
	  						}
	  						
	  						comment.startHtml = startHtml;
					   		comment.userHasProfile = function () {
					   			if ($.isEmptyObject(comment.user_info)) {
					   				return false;
					   			}
					   			
					   			return $.trim(comment.user_info.headerimg) != '';
					   		}
					   		
					   		comment.hasPhoto = function () {
					   			if (typeof comment.photos == 'undefined') {
					   				return false;
					   			}
					   			
					   			return !$.isEmptyObject(comment.photos);
					   		}
					   		
					   		if (typeof comment.reply != 'undefined') {
					   			comment.hasReply = true;
					   			
					   			comment.reply.beauticianHasProfile = function () {
					   				return $.trim(comment.reply.beautician.profile) != '';
					   			}
					   			
					   			comment.reply.hasPhoto = typeof comment.reply.photos != 'undefined' && $.isEmptyObject(comment.reply.photos);
					   		}
					   		
					   		itemHtml += Mustache.render(itemTemplete, comment);
			      		}
            		}
	               
            		itemHtmlObj = $(itemHtml);
	                // 为了测试，延迟1秒加载
	                setTimeout(function(){
	                    $('.lists').append(itemHtmlObj);
	                    me.resetload();
	                },1000);
	                
	                if (result.hasMore) {
	                	nextPage = result.nextPage;
	                } else {
	                	hasMore = false;
	                }
            	}
            },
            error: function(xhr, type){
                alert('Ajax error2!');
                me.resetload();
            }
        });
	}
    $(function () {
   	   $(window).scroll(function() {
   		  if ($(document).scrollTop() >= $(document).height() - $(window).height()-100) {
   				alert("现在开始加载数据");
   				return false;
   			}
   		});
	});
    </script>
    <if condition="$hasMore">
   	<script>hasMore = true;</script>
    </if>
    <include file="Public/beautician-footer" /> 
</body>
</html>